package com.example.myapplication;

import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.Log;

/**
 * =======================================================================================
 * 作    者：caoxinyu
 * 创建日期：2020/7/10.
 * 类的作用:
 * 修订历史：
 * =======================================================================================
 */
public class CustomLongClickView extends androidx.appcompat.widget.AppCompatButton {

    //一定要有一个默认的长按时间 不然如果为0的话 点击也会直接相应长按的listener 并且不会响应点击时间
    private long mLongClickDelayTime = 1500;

    public CustomLongClickView(Context context) {
        super(context);
    }

    public CustomLongClickView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public CustomLongClickView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    public boolean postDelayed(Runnable action, long delayMillis) {
        boolean mIsLong = false;
        if (TextUtils.equals("CheckForLongPress",action.getClass().getSimpleName())) {
            mIsLong = true;
        }
        Log.d("CustomLongClickView", "action:" + action);
        return super.postDelayed(action, mIsLong ? mLongClickDelayTime : delayMillis);

    }

    public void  setLongClickTime(long delayMillis){
        mLongClickDelayTime = delayMillis;
    }
}

